//
//  MyselfViewController.m
//  MapEXPO
//
//  Created by 洪雯 on 16/4/2.
//  Copyright © 2016年 洪雯. All rights reserved.
//

#import "MyselfViewController.h"
#import "MyCollectionViewCell.h"
#import "XFLoginViewController.h"
#import "Demo5HeaderView.h"
#import "StretchyHeaderCollectionViewLayout.h"

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)

NSString * const kCellId = @"Cell";
NSString * const kHeaderId = @"Header";

@interface MyselfViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
//@property (nonatomic, strong) UITableView * tableView;

@property (nonatomic , strong) UICollectionView *collectionView;

@end

@implementation MyselfViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];

}

- (void)initView
{
    StretchyHeaderCollectionViewLayout *stretchyLayout = [[StretchyHeaderCollectionViewLayout alloc] init];
    //stretchyLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    stretchyLayout.itemSize = CGSizeMake(SCREEN_WIDTH, 50);
    stretchyLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 120);
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64) collectionViewLayout:stretchyLayout];
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.alwaysBounceVertical = YES;
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    
    [self.view addSubview:_collectionView];
    
    [_collectionView registerClass:[Demo5HeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderId];
    
    [_collectionView registerNib:[UINib nibWithNibName:@"MyCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"Cell"];
}
#pragma mark UICollectionViewDataSource, UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 1;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader) {
        Demo5HeaderView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kHeaderId forIndexPath:indexPath];
        headView.iconName = [NSString stringWithFormat:@"shiyuanhui.jpg"];
        return headView;
    }
    return nil;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    XFLoginViewController *loginVc = [[XFLoginViewController alloc]init];
    [self presentViewController:loginVc animated:YES completion:nil];
}

@end
